package com.eigaland.change_machine.business.login

import com.eigaland.change_machine.APP
import com.eigaland.change_machine.BuildConfig
import com.eigaland.change_machine.displaymodel.HomeDisplayModel
import com.eigaland.change_machine.displaymodel.IDisplayModel
import com.eigland.eigaland_lib.base.BaseRepository
import com.eigland.eigaland_lib.model.*
import com.eigland.eigaland_lib.network.LoginService
import com.eigaland.change_machine.business.network.RetrofitClient
import com.eigaland.change_machine.util.UserManager
import movie6.posprintercept2.extensions.saveCinemaId
import movie6.posprintercept2.extensions.saveSec
import movie6.posprintercept2.extensions.saveToken

public class LoginFragmentRepository : BaseRepository() {

    suspend fun registerDevice(deviceId: String?): HomeDisplayModel?{
         var request = RegisterDeviceRequest(deviceId!!)
        var displayModel = HomeDisplayModel()
        var result = RetrofitClient.getService(LoginService::class.java,BuildConfig.domain).registerDevice(request).await()


        result.success?.let {
            displayModel.deviceSecret = it.device?.secret.toString()
            APP.app.saveSec(displayModel.deviceSecret)
            displayModel.loginStatus = IDisplayModel.SUCCESS_STATUS
        }
        result.error?.message?.let {
            displayModel.errorMsg =it
            displayModel.loginStatus = IDisplayModel.ERROR_STATUS
        }

        return displayModel

    }



}